<html>
	<head>
		<title>选择客户</title>
		<link href="/stylesheets/framework.css" media="screen" rel="Stylesheet" type="text/css" />
		<!--Start-->
  <%= javascript_include_tag "prototype" %>
		<script type="text/javascript">
			var oGoods=new Array();
			function queryProduct(){
                                //debugger;
				var url = '/ajax/get_agent';
				//var pars = 'agent_part=' + $F('agent_part') + '&agent_name=' + $F('agent_name');
                                var pars = '';
                                if ( $F('agent_name') != '' && $F('agent_part') != '' )
                                        pars = 'agent_name=' + encodeURI($F('agent_name')) + '&agent_part' + encodeURI($F('agent_part')); 
                                else if ( $F('agent_name') != '' )
                                        pars = 'agent_name=' + encodeURI($F('agent_name'));
                                else if ( $F('agent_part') != '' )
                                        pars = 'agent_part=' +encodeURI($F('agent_part')); 
                                var myAjax = new Ajax.Request(url,{
                                                                        method: 'get', 
                                                                        parameters:pars, 
                                                                        onComplete: showResponse
                                                                  });
			}
                        
			function showResponse(originalRequest){
				var oXML = originalRequest.responseXML;   
				if (oXML==null){
					alert("无法载入客户信息,请稍候再试.");
					return 0;
				}
				var oNodeList=oXML.getElementsByTagName("agent");
				var nodeLength=oNodeList.length;
				if (nodeLength==0){
					alert("没有查到相关客户,请重新检索.");
					return 0;
				}
				var sHTML="";
				for(var i=0;i<nodeLength;i++){
					var oNode=oNodeList[i];
					oGoods[i]={	name: oNode.getAttribute("name"),
					        id: oNode.getAttribute("id"),
							part: oNode.getAttribute("part"),
							person: oNode.getAttribute("person"),
							phone: oNode.getAttribute("phone"),
							address1: oNode.getAttribute("address1"),
							fax: oNode.getAttribute("fax")
					}
					sHTML	+='<tr id="LIST_TB_CONTENT2">'
							+ '<td>'+oGoods[i].name+'</td>'
							+ '<td>'+oGoods[i].part+'</td>'
							+ '<td>'+oGoods[i].person+'</td>'
							+ '<td>'+oGoods[i].phone+'</td>'
							//+ '<td>'+oGoods[i].address1+'</td>'
							+ '<td><input type="radio" name="rdoSelectGoods" id="rdoSelectGoods'+i+'"/></td>'
							+ '</tr>';
				}
				$('divGoodsDetail').innerHTML	='<table id="LIST_TB" align="center" border="0">'
												+'<tbody>'
												+'<tr id="LIST_TB_TITLE">'
												+'<td nowrap="nowrap">客户名称</td>'
												+'<td nowrap="nowrap">客户地区</td>'
												+'<td nowrap="nowrap">联系人</td>'
												+'<td nowrap="nowrap">联系电话</td>'
												//+'<td nowrap="nowrap">联系地址</td>'
												+'<td colspan="3">选择</td>'
												+'</tr>'
												+sHTML;
												+'</tbody>'
												+'</table>';
				$("rdoSelectGoods0").checked=true;
				$("divReturn").style.display="block";
                        }
			function returnBuyer(){
			     var i;
			     var l=oGoods.length;
			     for (i=0;i<l;i++)
					if ($("rdoSelectGoods"+i).checked==true) break;
				if (window.opener!=null) window.opener.addAgent(oGoods[i].id,oGoods[i].name,oGoods[i].person,oGoods[i].phone,oGoods[i].address1,oGoods[i].fax);
				window.close();
			}

                        

		</script>
		<!--End-->
	</head>
	<body>
	<div style="height: 25px;"></div>
	<form id="input-form" action="/sale/select_product" method="post">
<div style="text-align: center;">
	<input name="optype" value="search" type="hidden">
	客户名称：<input id="agent_name" type="text"  maxlength="20"/>&nbsp;&nbsp;&nbsp; 
	客户地区：<input id="agent_part" type="text"  maxlength="20"/>&nbsp;<input value="查询" type="button" class='sub' onclick="queryProduct();" />
</div>
</form>

<input name="optype" value="select" type="hidden">
<div id="divGoodsDetail" style="text-align: center;"></div>
<div id="divReturn" style="display: none;">
<div style="text-align: center;"><input type="button" class='sub' value="确定" onclick="returnBuyer()" /></div>
</div>
<div style="height: 10px;"></div>
</body></html>
